package cn.gok;

import java.lang.reflect.Constructor;
import java.lang.reflect.Field;
import java.lang.reflect.Method;

class Book {
    private int bid;
    private String name;
    private float price;

    public Book(int bid, String name, float price) {
        this.bid = bid;
        this.name = name;
        this.price = price;
    }

    public void sell() {
        System.out.println(this.name + "被卖了");
    }

    private void sell(float price, String person) {
        System.out.println(this.name + "卖给了" + person + ",卖了" + price + "元");
    }

    @Override
    public String toString() {
        return "Book{" +
                "bid=" + bid +
                ", name='" + name + '\'' +
                ", price=" + price +
                '}';
    }
}

public class 作业七 {
    public static void main(String[] args) throws Exception {
        Class c = Class.forName("cn.gok.Book");
        for (Field field : c.getDeclaredFields()) {
            System.out.println(field);
        }
        System.out.println("----------------");
        for (Method method : c.getDeclaredMethods()) {
            System.out.println(method);
        }
        System.out.println("----------------");
        Constructor constructor = c.getConstructor(int.class, String.class, float.class);
        Book book = (Book) constructor.newInstance(1, "西游记", 60f);
        Method method = c.getDeclaredMethod("sell");
        method.invoke(book);
        System.out.println("----------------");
        Method method1 = c.getDeclaredMethod("sell", float.class, String.class);
        method1.setAccessible(true);
        method1.invoke(book, 70f, "AA");
    }
}
